﻿using Microsoft.AspNetCore.Mvc;
using System.Web;

namespace SwaggerDoc.Api.Controllers
{
    /// <summary>
    /// 主控制器
    /// </summary>
    [ApiController]
    [Route("swag/[controller]/[action]")]
    public class DocController : Controller
    {
        /// <summary>
        /// Str
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public string Str()
        {
            Request.Headers.TryGetValue("uid", out var uid);
            Request.Headers.TryGetValue("name", out var name);
            Request.Headers.TryGetValue("roleids", out var roleids);
            Request.Headers.TryGetValue("jti", out var jti);
            Request.Headers.TryGetValue("aud", out var aud);
            Request.Headers.TryGetValue("iss", out var iss);
            Request.Headers.TryGetValue("loginer", out var loginer);
            Request.Headers.TryGetValue("nbf", out var nbf);
            Request.Headers.TryGetValue("exp", out var exp);

            return $"uid:{uid};name:{HttpUtility.UrlDecode(name)};roleids:{roleids};iss:{iss};loginer:{loginer}";
        }

        /// <summary>
        /// Limit
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public string Limit()
        {
            return "Limit";
        }

        /// <summary>
        /// Cache
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public string Cache()
        {
            return DateTime.Now.ToString();
        }

        /// <summary>
        /// Break
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public string Break()
        {
            Thread.Sleep(3000);
            return "Break";
        }
    }
}
